/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Monopol.Events;

import ClientBL.Event;
import GameServer.ServerService;
import GameServer.eEventsID;
import Monopol.MonopolExceptions.MonopolErrors;
import java.awt.EventQueue;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Noa
 */
public class MonopolyGameEvents extends EventQueue {

    private List<Event> allEvents;
    private static MonopolyGameEvents instance;

    static {
	instance = new MonopolyGameEvents();
    }

    public MonopolyGameEvents() {
    }

    public static MonopolyGameEvents getInstance() {
	return instance;
    }

    public List<Event> getEvents() {
	allEvents = ServerService.getInstance().getGameEvents();
	// Return All the Game Events
	return allEvents;
    }

    public eEventsID parseEvent(Integer eventID) {
	return eEventsID.find(eventID);
    }

    public void setCubesEvent(Integer playerID, Integer eventID, Integer[] cubes) {
	try {
	    // Send the Server an Event on the New manulay setted Dices
	    ServerService.getInstance().setDiceRollResults(playerID, eventID, cubes[0], cubes[1]);
	} catch (MonopolErrors ex) {
	    Logger.getLogger(MonopolyGameEvents.class.getName()).log(Level.SEVERE, null, ex);
	}
    }

    public Boolean setBuyAsset(Integer playerID, Integer eventID, Boolean buyAsset) {
	try {
	    // Send the Server an Event on an Asset Buying
	    return ServerService.getInstance().buyAsset(playerID,eventID, buyAsset);
	} catch (MonopolErrors ex) {
	    Logger.getLogger(MonopolyGameEvents.class.getName()).log(Level.SEVERE, null, ex);
	}
	return false;
    }

    public Boolean setBuyHouse(Integer playerID, Integer eventID, Boolean addHouse) {
	try {
	    // Send the Server an Event on an Adding a House
	    return ServerService.getInstance().buyHouse(playerID ,eventID,  addHouse);
	} catch (MonopolErrors ex) {
	    Logger.getLogger(MonopolyGameEvents.class.getName()).log(Level.SEVERE, null, ex);
	}
	return false;
    }

    public void setResignedPlayer(Integer playerID) throws MonopolErrors {
	// Send the Server an Event on the Resigned player
	ServerService.getInstance().resign(playerID);
    }

    public Timer startPollingEvents(String taskName, TimerTask task){
	return ServerService.getInstance().startPolling(taskName, task, 5, 4);
    }
}
